package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.domain.dao.WorkOrderPersonDao;
import com.xbongbong.saas.domain.entity.WorkOrderPersonEntity;
import com.xbongbong.saas.model.WorkOrderPersonModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author ly1666
 * @date 2019/3/15 上午11:24
 * @since v1.0
 * @version v1.0
 */
@Service("WorkOrderPersonModel")
public class WorkOrderPersonModelImpl implements WorkOrderPersonModel {
    @Resource
    private WorkOrderPersonDao workOrderPersonDao;

    @Override
    public Integer insert(WorkOrderPersonEntity entity) throws XbbException {
        long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return workOrderPersonDao.insert(entity);
    }

    @Override
    public Integer update(WorkOrderPersonEntity entity) throws XbbException {
        return workOrderPersonDao.update(entity);
    }

    @Override
    public List<WorkOrderPersonEntity> findEntitys(Map<String, Object> param){

        return workOrderPersonDao.findEntitys(param);

    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return workOrderPersonDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public WorkOrderPersonEntity getByKey(Long key, String corpid){
        return workOrderPersonDao.getByKey(key, corpid);
    }

    @Override
    public Integer save(WorkOrderPersonEntity workOrderPersonEntity) throws XbbException{
        if (workOrderPersonEntity.getId() == null || Objects.equals(0L, workOrderPersonEntity.getId())){
            return insert(workOrderPersonEntity);
        }else {
            return update(workOrderPersonEntity);
        }
    }
    @Override
    public Integer deleteByKey(Long key, String corpid){
        return workOrderPersonDao.deleteByKey(key, corpid);
    }
}
